/**
 * 
 */
package com.whu.waterworks.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate4.HibernateTemplate;

import com.whu.waterworks.dao.QualityNonNormDao;
import com.whu.waterworks.model.QualityNonNormol;

/**
 * @author： Joymin
 * @date：2016-4-3 下午5:12:19
 * 说明: 
 */
public class QualityNonNormDaoImpl implements QualityNonNormDao{
	
	private HibernateTemplate hibernateTemplate;
	
		
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNonNormDao#saveQualityNonNormol(com.whu.waterworks.model.QualityNonNormol)
	 */
	@Override
	public boolean saveQualityNonNormol(QualityNonNormol norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.save(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNonNormDao#updateQualityNonNormol(com.whu.waterworks.model.QualityNonNormol)
	 */
	@Override
	public boolean updateQualityNonNormol(QualityNonNormol norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.merge(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNonNormDao#delQualityNonNormol(com.whu.waterworks.model.QualityNonNormol)
	 */
	@Override
	public boolean delQualityNonNormol(QualityNonNormol norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.delete(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNonNormDao#getLimitedQualityNonNormol()
	 */
	@Override
	public QualityNonNormol getLimitedQualityNonNormol() {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<QualityNonNormol> rs =(ArrayList<QualityNonNormol>) hibernateTemplate.find("from QualityNonNormol _QualityNonNormol where _QualityNonNormol.type='1'");
		if(null!=rs && rs.size()>0){
			return rs.get(0);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNonNormDao#getQualityNonNormolById(java.lang.String)
	 */
	@Override
	public QualityNonNormol getQualityNonNormolById(String id) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<QualityNonNormol> rs =(ArrayList<QualityNonNormol>) hibernateTemplate.find("from QualityNonNormol _QualityNonNormol where _QualityNonNormol.id='"+id+"'");
		if(null!=rs && rs.size()>0){
			return rs.get(0);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNonNormDao#getQualityNonNormolByIdAndTime(java.lang.String, java.lang.String)
	 */
	@Override
	public List<QualityNonNormol> getQualityNonNormolByIdAndTime(
			String waterPlantId, String time) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<QualityNonNormol> rs =(ArrayList<QualityNonNormol>) hibernateTemplate.find("" +
				"from QualityNonNormol _QualityNonNormol where _QualityNonNormol.waterplantId='"+waterPlantId+"' and _QualityNonNormol.time='"+time+"'");
		if(null!=rs && rs.size()>0){
			return rs;
		}
		return null;
	}
//zhoululu
	@Override
	public List<QualityNonNormol> getQualityNonNormols(String code,
			String starttime, String endtime) {
		@SuppressWarnings("unchecked")
		ArrayList<QualityNonNormol> qnns=(ArrayList<QualityNonNormol>) hibernateTemplate.find("from QualityNonNormol qnn where qnn.waterplantId='"+code+"' and qnn.time between '"+
				starttime+"' and '"+endtime+"'");
		return qnns;
	}
}
